<template lang='pug'>

</template>
<script>
import { xyzToCart2,xyzToCart3 } from '../material/pntsTrans'
export default {
    name: 'c_tech_wall',
    data() {
        return {
            viewer:null,
            Cesium:null,
            gp_tech_wall:null
        }
    },
    props: {
        arrda: {
            type:Array,
            default:[]
        }
    },
    watch: {
        arrda: {
            handler(){
                if(this.Cesium && this.viewer)this.load()
            }
        },
        deep: true,
    },
    mounted () {
        let t=this
        t.$nextTick(()=>{
            t.viewer=t.$parent.viewer
            t.Cesium=t.$parent.Cesium
            let {Cesium,viewer} =this
            t.gp_tech_wall=new Cesium.CustomDataSource("tech_wall")
            viewer.dataSources.add(t.gp_tech_wall)
            t.load()
        })
    },
    methods:{
        load() {
            let t=this
            let {Cesium,viewer} =this   
            t.gp_tech_wall.entities.removeAll()
            t.arrda.forEach(opt => {
                let pnts=opt.positions
                let color= opt.color||Cesium.Color.RED
                let type=opt.type||'oldWall' //''贴地' ground,water,wall,heatmap,plane
                let name=`tech_wall_${type}`,wall={},polygon={}
                let height=opt.height||100
                if(type=='water'){
                    color=opt.color||Cesium.Color.BLUE//水体颜色
                    polygon={
                        hierarchy: new Cesium.PolygonHierarchy(
                            Cesium.Cartesian3.fromDegreesArray(xyzToCart2(pnts))
                        ),
                        material:color.withAlpha(0.7),
                        extrudedHeight:height
                    }
                }
                if(type=='heatmap'){
                }
                if(type=='plane' ){
                    polygon={
                        hierarchy: new Cesium.PolygonHierarchy(
                            Cesium.Cartesian3.fromDegreesArray(xyzToCart2(pnts))
                        ),
                        material:color.withAlpha(0.8),
                        height
                    }
                }
                if(type=='oldWall'){ //wall由两部分组成
                    wall={
                        positions: Cesium.Cartesian3.fromDegreesArrayHeights(opt.positions),
                        material:new Cesium.ColorMaterialProperty(
                            new Cesium.CallbackProperty(function(time, x) {
                            var alp = 0.5 * Math.abs(Math.sin(new Date().getTime() / 500)) +0.2
                            return color.withAlpha(alp)
                        }, false))
                    }
                }
                if(type=='wall'){ //wall由两部分组成
                    wall={
                        positions: Cesium.Cartesian3.fromDegreesArrayHeights(opt.positions),
                        material:matGrdImg(color),
                        outlineColor:color,
                        outline:true,
                        outlineWidth:opt.outlineWidth||1
                    }
                }
                if(type=='build'){
                    polygon={
                        hierarchy: new Cesium.PolygonHierarchy(
                            Cesium.Cartesian3.fromDegreesArray(xyzToCart2(pnts))
                        ),
                        material:matBreath(color),
                        height
                    }
                    wall={
                        positions: Cesium.Cartesian3.fromDegreesArrayHeights(xyzToCart3(pnts,height,true)),
                        material:matGrdImg(color),
                        outlineColor:color,
                        outline:true,
                        outlineWidth:opt.outlineWidth||1
                    }
                }
                t.gp_tech_wall.entities.add({name,wall,polygon})
            })
        }
    }
}
</script>